/*package org.itboys.trade.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.itboys.commons.CommonConstants;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.commons.utils.cookie.CookieUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.product.service.ProductService;
import org.itboys.trade.entity.Cart;
import org.itboys.trade.service.CartService;
import org.itboys.trade.service.OrderService;
import org.omg.PortableServer.ServantLocatorPackage.CookieHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController 
@RequestMapping("/cart") 
public class CartController  extends BaseController{

	@Autowired
	private CartService cartService;
	@Autowired
	private ProductService productService;
	
	*//**
	 * 跳转到购物车页面
	 * @param request
	 * @param response
	 * @return
	 *//*
	@RequestMapping("/cartIndex")
	public ModelAndView toListVM(Model model,HttpServletRequest request, HttpServletResponse response) {
		boolean isLogin = false ;
		String userId;//如果登录状态
		List<Cart> carts;
		if(isLogin){
			//userId = SessionHolder.getMemberId();
			Long memberId = 0l;
			carts = cartService.getCartListByMemberId(memberId);
		}else{
			userId = CookieUtils.getValueFromCookie(request, "cookieId");
			carts = cartService.getCartListByCookiesId(userId);
		}
		
		//productService.getById(id);
		model.addAttribute("carts", carts);
		return new ModelAndView("cart/cart");
	}
	*//**
	 * 添加商品到购物车
	 * @param request
	 * @param cart
	 * @param response
	 *//*
	@ResponseBody
	@RequestMapping("/addCart")
	public void addProduct(HttpServletRequest request,
			Cart cart,HttpServletResponse response){
		try{
			cartService.save(cart);
			AjaxUtils.renderText(response, CommonConstants.SUCCESS);
		}catch(Exception e){
			e.printStackTrace();
			AjaxUtils.renderText(response, CommonConstants.FAIL);
		}
	}
	
	*//**
	 * 购物车中删除商品
	 * @param request
	 * @param cartId
	 * @param response
	 *//*
	
	@ResponseBody
	@RequestMapping("/deleteCartItem")
	public void deleteCart(HttpServletRequest request,
			Long cartId,HttpServletResponse response){
		try{
			cartService.delete(cartId);
			AjaxUtils.renderText(response, CommonConstants.SUCCESS);
		}catch(Exception e){
			e.printStackTrace();
			AjaxUtils.renderText(response, CommonConstants.FAIL);
		}
	}
	
	*//**
	 * 产品数量+1
	 * @param request
	 * @param productId
	 * @param response
	 *//*
	@ResponseBody
	@RequestMapping("/addNum")
	public void addProductNum(HttpServletRequest request,
			Long cartId,HttpServletResponse response) {
		try{
			Cart cart = cartService.getCart(cartId);
			cart.setNum(cart.getNum()+1);
			cartService.update(cart);
			AjaxUtils.renderText(response, CommonConstants.SUCCESS);
		}catch(Exception e){
			AjaxUtils.renderText(response, CommonConstants.FAIL);
		}
	}
	
	
	*//**
	 * 产品数量减一
	 * @param request
	 * @param productId
	 * @param response
	 *//*
	
	@ResponseBody
	@RequestMapping("/subNum")
	public void subProductNum(HttpServletRequest request, 
			Long cartId,HttpServletResponse response) {
		try{
			
			Cart cart = cartService.getCart(cartId);
			cart.setNum(cart.getNum()-1>=0?cart.getNum()-1:0);
			cartService.update(cart);
			AjaxUtils.renderText(response, CommonConstants.SUCCESS);
		}catch(Exception e){
			AjaxUtils.renderText(response, CommonConstants.FAIL);
		}
	}
	
	@ResponseBody
	@RequestMapping("/updateNum")
	public void updateProductNum(HttpServletRequest request, 
			Long cartId,HttpServletResponse response) {
		try{
			
			Cart cart = cartService.getCart(cartId);
			cart.setNum(cart.getNum()-1>=0?cart.getNum()-1:0);
			cartService.update(cart);
			AjaxUtils.renderText(response, CommonConstants.SUCCESS);
		}catch(Exception e){
			AjaxUtils.renderText(response, CommonConstants.FAIL);
		}
	}
	
	*//**
	 * 购物车删除产品
	 * @param request
	 * @param productIds
	 * @param response
	 *//*
	
	@ResponseBody
	@RequestMapping("/delete")
	public void deleteProduct(HttpServletRequest request,
			Long cartId,HttpServletResponse response) {
		try{
			boolean flag = cartService.delete(cartId);
			AjaxUtils.renderText(response, CommonConstants.SUCCESS);
		}catch(Exception e){
			AjaxUtils.renderText(response, CommonConstants.FAIL);
		}
	}
	
	*//**
	 * 购物车转订单
	 * @param request
	 * @param productId
	 * @param response
	 * @return
	 *//*
	
	@RequestMapping("/cartToOrder")
	public ModelAndView cartToOrder(HttpServletRequest request,
			Long productId,HttpServletResponse response) {
		return new ModelAndView("/seller/order");
	}
}
*/